/**
 * 
 */
package it.agm.fanta.adapter;

import it.agm.fanta.fragment.PartitaLegaFragment;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

/**
 * @author alberto
 *
 */
public class FragmentListPagerAdapter extends FragmentPagerAdapter {

	private final List<Fragment> fragments;
	
	/**
     * @param fragmentManager
     * @param fragments
     */
    public FragmentListPagerAdapter(FragmentManager fragmentManager, List<Fragment> fragmentsList) {
        super(fragmentManager);
        this.fragments = fragmentsList;
    }
   

	@Override
    public Fragment getItem(final int position) {
		
		PartitaLegaFragment f = new PartitaLegaFragment();
		f.setTrasferta(((PartitaLegaFragment) fragments.get(position)).isTrasferta());
        return f;
    }
	
//	@Override
//	public int getItemPosition(Object object) {
//		PartitaLegaFragment f = (PartitaLegaFragment) object;
//		   if (f != null) {
//		      f.update();
//		   }
//		  return super.getItemPosition(object);
//    }

    @Override
    public int getCount() {
        return fragments.size();
    }
    
    @Override
    public String getPageTitle(int position) {
      return ((PartitaLegaFragment)fragments.get(position)).getTitle();
    }
    
//    @Override
//    public void destroyItem(ViewGroup container, int position, Object object) {
//       // Log.d(TAG, "destroyItem " + position);
//    	fragments.remove(position);
//        super.destroyItem(container, position, object);
//    }


}
